names(data)<-gsub("ms57_","",names(data))
d1<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 63.csv")
names(data)<-gsub("ms63_","",names(data))
d2<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 85.csv")
names(data)<-gsub("ms85_","",names(data))
d3<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 92.csv")
names(data)<-gsub("ms92_","",names(data))
d4<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 107.csv")
names(data)<-gsub("ms107_","",names(data))
d5<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 117.csv")
names(data)<-gsub("ms117_","",names(data))
d6<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 134.csv")
names(data)<-gsub("ms134_","",names(data))
d7<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 157.csv")
names(data)<-gsub("ms157_","",names(data))
d8<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 178.csv")
names(data)<-gsub("ms178_","",names(data))
d9<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 198.csv")
names(data)<-gsub("ms198_","",names(data))
d10<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 219.csv")
names(data)<-gsub("ms219_","",names(data))
d11<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 236.csv")
names(data)<-gsub("ms236_","",names(data))
d12<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 253.csv")
names(data)<-gsub("ms253_","",names(data))
d13<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 271.csv")
names(data)<-gsub("ms271_","",names(data))
d14<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 288.csv")
names(data)<-gsub("ms288_","",names(data))
d15<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 322.csv")
names(data)<-gsub("ms322_","",names(data))
d16<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 335.csv")
names(data)<-gsub("ms335_","",names(data))
d17<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 345.csv")
names(data)<-gsub("ms345_","",names(data))
d18<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 358.csv")
names(data)<-gsub("ms358_","",names(data))
d19<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 368.csv")
names(data)<-gsub("ms368_","",names(data))
d20<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 379.csv")
names(data)<-gsub("ms379_","",names(data))
d21<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 389.csv")
names(data)<-gsub("ms389_","",names(data))
d22<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 400.csv")
names(data)<-gsub("ms400_","",names(data))
d23<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 417.csv")
names(data)<-gsub("ms417_","",names(data))
d24<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 426.csv")
names(data)<-gsub("ms426_","",names(data))
d25<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 434.csv")
names(data)<-gsub("ms434_","",names(data))
d26<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 440.csv")
names(data)<-gsub("ms440_","",names(data))
d27<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 448.csv")
names(data)<-gsub("ms448_","",names(data))
d28<-data
d1$tsstart
min(d1$tsstart)
min(as.character(d1$tsstart))
min(as.character(d1$tsend))
max(as.character(d1$tsstart))
d1$tsstart
l1<-list(d1,d2,d3,d4,d5,d6,d7,d8,d9,d10,d11,d12,d13,d14,d15,d16,d17,
d18,d19,d20,d21,d22,d23,d24,d25,d26,d27,d28)
for(i in 1:length(l1)){
d<-l1[[i]]
d<-subset(d,select=c("prim_key","hu001","hu001_nr_dk"))
d$begin<-min(as.character(d$tsstart))
assign(paste("d", i, sep = ""),d)
}
warnings()
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/short/alp_74.csv")
View(data)
names(data)<-gsub("ms74_","",names(data))
d1.s<-data
list.files("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/short/")
short.surveys<-list.files("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/short/")
short.surveys
paste("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/short/",
"alp_298.csv")
paste("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/short/",
"alp_298.csv",sep="")
length("alp")
nchar("alp")
nchar("alp_103.csv")
substr("alp_103.csv",5,7)
rm(list=ls())
library("tidyr")
library("reshape")
# import long survey
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 57.csv")
names(data)<-gsub("ms57_","",names(data))
d1<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 63.csv")
names(data)<-gsub("ms63_","",names(data))
d2<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 85.csv")
names(data)<-gsub("ms85_","",names(data))
d3<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 92.csv")
names(data)<-gsub("ms92_","",names(data))
d4<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 107.csv")
names(data)<-gsub("ms107_","",names(data))
d5<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 117.csv")
names(data)<-gsub("ms117_","",names(data))
d6<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 134.csv")
names(data)<-gsub("ms134_","",names(data))
d7<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 157.csv")
names(data)<-gsub("ms157_","",names(data))
d8<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 178.csv")
names(data)<-gsub("ms178_","",names(data))
d9<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 198.csv")
names(data)<-gsub("ms198_","",names(data))
d10<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 219.csv")
names(data)<-gsub("ms219_","",names(data))
d11<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 236.csv")
names(data)<-gsub("ms236_","",names(data))
d12<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 253.csv")
names(data)<-gsub("ms253_","",names(data))
d13<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 271.csv")
names(data)<-gsub("ms271_","",names(data))
d14<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 288.csv")
names(data)<-gsub("ms288_","",names(data))
d15<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 322.csv")
names(data)<-gsub("ms322_","",names(data))
d16<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 335.csv")
names(data)<-gsub("ms335_","",names(data))
d17<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 345.csv")
names(data)<-gsub("ms345_","",names(data))
d18<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 358.csv")
names(data)<-gsub("ms358_","",names(data))
d19<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 368.csv")
names(data)<-gsub("ms368_","",names(data))
d20<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 379.csv")
names(data)<-gsub("ms379_","",names(data))
d21<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 389.csv")
names(data)<-gsub("ms389_","",names(data))
d22<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 400.csv")
names(data)<-gsub("ms400_","",names(data))
d23<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 417.csv")
names(data)<-gsub("ms417_","",names(data))
d24<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 426.csv")
names(data)<-gsub("ms426_","",names(data))
d25<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 434.csv")
names(data)<-gsub("ms434_","",names(data))
d26<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 440.csv")
names(data)<-gsub("ms440_","",names(data))
d27<-data
data<-read.csv("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/alp 448.csv")
names(data)<-gsub("ms448_","",names(data))
d28<-data
short.surveys<-list.files("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/short/")
for survey in short.surveys {
for i in short.surveys {
for (i in short.surveys) {
path<-paste("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/short/",
i,sep="")
data<-read.csv(path)
if nchar(i)==11{num<-substr(i,5,7) }
else {num<-substr(i,5,6)}
pref<-paste("ms",num,sep="")
names(data)<-gsub(pref,"",names(data))
d.name<-paste("d",num,"s",sep=".")
assign(d.name,date)
}
i
for (i in short.surveys) {
path<-paste("~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/financial crisis survey original/short/",
i,sep="")}
path
data<-read.csv(path)
i
if nchar(i)==11{num<-substr(i,5,7) }
if (nchar(i)==11) {num<-substr(i,5,7) }
else {num<-substr(i,5,6)}
if (nchar(i)==11) {num<-substr(i,5,7) }
if else (nchar(i)==10) {num<-substr(i,5,6)}
if (nchar(i)==11) {num<-substr(i,5,7) }
else if (nchar(i)==10) {num<-substr(i,5,6)}
if (nchar(i)==11) {
num<-substr(i,5,7)
}
else if (nchar(i)==10) {
num<-substr(i,5,6)
}
else {print("Something weird")}
if (nchar(i)==11) {
num<-substr(i,5,7)
} else if (nchar(i)==10) {
num<-substr(i,5,6)
} else {print("Something weird")}
num
pref<-paste("ms",num,sep="")
names(data)<-gsub(pref,"",names(data))
d.name<-paste("d",num,"s",sep=".")
assign(d.name,date)
name
d.name
?assign
assign(d.name,data)
source('~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/R/extra/load and clean financial crisis data.R')
house.tr<-matrix(c(c1,c2,c3),nrow=3)
rm(list=ls())
load("/Users/manguito/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/R/panel_uh.RData")
data<-panel.uh
data$h2_1month.cleaned<-data$h2_1month
data$h2_3month.cleaned<-data$h2_3month
data$h2_1year.cleaned<-data$h2_1year
data$h2_1month.cleaned[data$h2_1month>2*data$housing.price|data$h2_1month<0.5*data$housing.price|
data$h2_3month>2*data$housing.price|data$h2_3month<0.5*data$housing.price|
data$h2_1year>2*data$housing.price|data$h2_1year<0.5*data$housing.price]<-"TR"
data$h2_3month.cleaned[data$h2_1month>2*data$housing.price|data$h2_1month<0.5*data$housing.price|
data$h2_3month>2*data$housing.price|data$h2_3month<0.5*data$housing.price|
data$h2_1year>2*data$housing.price|data$h2_1year<0.5*data$housing.price]<-"TR"
data$h2_1year.cleaned[data$h2_1month>2*data$housing.price|data$h2_1month<0.5*data$housing.price|
data$h2_3month>2*data$housing.price|data$h2_3month<0.5*data$housing.price|
data$h2_1year>2*data$housing.price|data$h2_1year<0.5*data$housing.price]<-"TR"
# What criteria should we use? For the gold and stock markets, the respondents had to say
# what the price of an asset that is worth $1000 today would be in 1 month, 3 months and 1 year,
# so for those markets I'd truncate respondents who had:
#
# 1. At least one reply >4000
# 2. All replies <100 or >2000
### truncation statistics
# house prices
n<-length(which(!is.na(data$h2_1month)))
na<-length(which(is.na(data$h2_1month)))
na2<-length(which(is.na(data$h2_1month.cleaned)))
n.tr1<-length(which(data$h2_1month.cleaned=="TR"))-(na-na2)
c1<-c(n,n.tr1,n.tr1/n*100)
n<-length(which(!is.na(data$h2_3month)))
na<-length(which(is.na(data$h2_3month)))
na2<-length(which(is.na(data$h2_3month.cleaned)))
n.tr3<-length(which(data$h2_3month.cleaned=="TR"))-(na-na2)
c2<-c(n,n.tr1,n.tr1/n*100)
n<-length(which(!is.na(data$h2_1year)))
na<-length(which(is.na(data$h2_1year)))
na2<-length(which(is.na(data$h2_1year.cleaned)))
n.tr12<-length(which(data$h2_1year.cleaned=="TR"))-(na-na2)
c3<-c(n,n.tr1,n.tr1/n*100)
house.tr<-matrix(c(c1,c2,c3),nrow=3)
house.tr
c1
house.tr
house.tr<-cbind(c1,c2,c3)
c1
house.tr
house.tr<-rbind(c1,c2,c3)
house.tr
source('~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/R/extra/truncation filter original.R', echo=TRUE)
data<-panel.uh
data$h2_1month.cleaned<-data$h2_1month
data$h2_3month.cleaned<-data$h2_3month
data$h2_1year.cleaned<-data$h2_1year
data$h2_1month.cleaned[data$h2_1month>2*data$housing.price|data$h2_1month<0.5*data$housing.price|
data$h2_3month>2*data$housing.price|data$h2_3month<0.5*data$housing.price|
data$h2_1year>2*data$housing.price|data$h2_1year<0.5*data$housing.price]<-"TR"
data$h2_3month.cleaned[data$h2_1month>2*data$housing.price|data$h2_1month<0.5*data$housing.price|
data$h2_3month>2*data$housing.price|data$h2_3month<0.5*data$housing.price|
data$h2_1year>2*data$housing.price|data$h2_1year<0.5*data$housing.price]<-"TR"
data$h2_1year.cleaned[data$h2_1month>2*data$housing.price|data$h2_1month<0.5*data$housing.price|
data$h2_3month>2*data$housing.price|data$h2_3month<0.5*data$housing.price|
data$h2_1year>2*data$housing.price|data$h2_1year<0.5*data$housing.price]<-"TR"
data<-panel.uh
data$e2_1month.cleaned<-data$e2_1month
data$e2_3month.cleaned<-data$e2_3month
data$e2_1year.cleaned<-data$e2_1year
data$e2_1month.cleaned[data$e2_1month>4000|data$e2_3month>4000|data$e2_1year>4000]<-"TR"
data$e2_1month.cleaned[data$e2_1month>2000 & data$e2_3month>2000 & data$e2_1year>2000]<-"TR"
data$e2_1month.cleaned[data$e2_1month<100 & data$e2_3month<100 & data$e2_1year<100]<-"TR"
data$e2_3month.cleaned[data$e2_1month>4000|data$e2_3month>4000|data$e2_1year>4000]<-"TR"
data$e2_3month.cleaned[data$e2_1month>2000 & data$e2_3month>2000 & data$e2_1year>2000]<-"TR"
data$e2_3month.cleaned[data$e2_1month<100 & data$e2_3month<100 & data$e2_1year<100]<-"TR"
data$e2_1year.cleaned[data$e2_1month>4000|data$e2_3month>4000|data$e2_1year>4000]<-"TR"
data$e2_1year.cleaned[data$e2_1month>2000 & data$e2_3month>2000 & data$e2_1year>2000]<-"TR"
data$e2_1year.cleaned[data$e2_1month<100 & data$e2_3month<100 & data$e2_1year<100]<-"TR"
data<-panel.uh
data$g2_1month.cleaned<-data$g2_1month
data$g2_3month.cleaned<-data$g2_3month
data$g2_1year.cleaned<-data$g2_1year
data$g2_1month.cleaned[data$g2_1month>4000|data$g2_3month>4000|data$g2_1year>4000]<-"TR"
data$g2_1month.cleaned[data$g2_1month>2000 & data$g2_3month>2000 & data$g2_1year>2000]<-"TR"
data$g2_1month.cleaned[data$g2_1month<100 & data$g2_3month<100 & data$g2_1year<100]<-"TR"
data$g2_3month.cleaned[data$g2_1month>4000|data$g2_3month>4000|data$g2_1year>4000]<-"TR"
data$g2_3month.cleaned[data$g2_1month>2000 & data$g2_3month>2000 & data$g2_1year>2000]<-"TR"
data$g2_3month.cleaned[data$g2_1month<100 & data$g2_3month<100 & data$g2_1year<100]<-"TR"
data$g2_1year.cleaned[data$g2_1month>4000|data$g2_3month>4000|data$g2_1year>4000]<-"TR"
data$g2_1year.cleaned[data$g2_1month>2000 & data$g2_3month>2000 & data$g2_1year>2000]<-"TR"
data$g2_1year.cleaned[data$g2_1month<100 & data$g2_3month<100 & data$g2_1year<100]<-"TR"
# What criteria should we use? For the gold and stock markets, the respondents had to say
# what the price of an asset that is worth $1000 today would be in 1 month, 3 months and 1 year,
# so for those markets I'd truncate respondents who had:
#
# 1. At least one reply >4000
# 2. All replies <100 or >2000
### truncation statistics
# house prices
n<-length(which(!is.na(data$h2_1month)))
na<-length(which(is.na(data$h2_1month)))
na2<-length(which(is.na(data$h2_1month.cleaned)))
n.tr1<-length(which(data$h2_1month.cleaned=="TR"))-(na-na2)
c1<-c(n,n.tr1,n.tr1/n*100)
n<-length(which(!is.na(data$h2_3month)))
n<-length(which(!is.na(data$h2_1month)))
na<-length(which(is.na(data$h2_1month)))
na2<-length(which(is.na(data$h2_1month.cleaned)))
na2
data<-panel.uh
data$h2_1month.cleaned<-data$h2_1month
data$h2_3month.cleaned<-data$h2_3month
data$h2_1year.cleaned<-data$h2_1year
data$h2_1month.cleaned[data$h2_1month>2*data$housing.price|data$h2_1month<0.5*data$housing.price|
data$h2_3month>2*data$housing.price|data$h2_3month<0.5*data$housing.price|
data$h2_1year>2*data$housing.price|data$h2_1year<0.5*data$housing.price]<-999999
data$h2_3month.cleaned[data$h2_1month>2*data$housing.price|data$h2_1month<0.5*data$housing.price|
data$h2_3month>2*data$housing.price|data$h2_3month<0.5*data$housing.price|
data$h2_1year>2*data$housing.price|data$h2_1year<0.5*data$housing.price]<-999999
data$h2_1year.cleaned[data$h2_1month>2*data$housing.price|data$h2_1month<0.5*data$housing.price|
data$h2_3month>2*data$housing.price|data$h2_3month<0.5*data$housing.price|
data$h2_1year>2*data$housing.price|data$h2_1year<0.5*data$housing.price]<-999999
data<-panel.uh
data$e2_1month.cleaned<-data$e2_1month
data$e2_3month.cleaned<-data$e2_3month
data$e2_1year.cleaned<-data$e2_1year
data$e2_1month.cleaned[data$e2_1month>4000|data$e2_3month>4000|data$e2_1year>4000]<-999999
data$e2_1month.cleaned[data$e2_1month>2000 & data$e2_3month>2000 & data$e2_1year>2000]<-999999
data$e2_1month.cleaned[data$e2_1month<100 & data$e2_3month<100 & data$e2_1year<100]<-999999
data$e2_3month.cleaned[data$e2_1month>4000|data$e2_3month>4000|data$e2_1year>4000]<-999999
data$e2_3month.cleaned[data$e2_1month>2000 & data$e2_3month>2000 & data$e2_1year>2000]<-999999
data$e2_3month.cleaned[data$e2_1month<100 & data$e2_3month<100 & data$e2_1year<100]<-999999
data$e2_1year.cleaned[data$e2_1month>4000|data$e2_3month>4000|data$e2_1year>4000]<-999999
data$e2_1year.cleaned[data$e2_1month>2000 & data$e2_3month>2000 & data$e2_1year>2000]<-999999
data$e2_1year.cleaned[data$e2_1month<100 & data$e2_3month<100 & data$e2_1year<100]<-999999
data<-panel.uh
data$g2_1month.cleaned<-data$g2_1month
data$g2_3month.cleaned<-data$g2_3month
data$g2_1year.cleaned<-data$g2_1year
data$g2_1month.cleaned[data$g2_1month>4000|data$g2_3month>4000|data$g2_1year>4000]<-999999
data$g2_1month.cleaned[data$g2_1month>2000 & data$g2_3month>2000 & data$g2_1year>2000]<-999999
data$g2_1month.cleaned[data$g2_1month<100 & data$g2_3month<100 & data$g2_1year<100]<-999999
data$g2_3month.cleaned[data$g2_1month>4000|data$g2_3month>4000|data$g2_1year>4000]<-999999
data$g2_3month.cleaned[data$g2_1month>2000 & data$g2_3month>2000 & data$g2_1year>2000]<-999999
data$g2_3month.cleaned[data$g2_1month<100 & data$g2_3month<100 & data$g2_1year<100]<-999999
data$g2_1year.cleaned[data$g2_1month>4000|data$g2_3month>4000|data$g2_1year>4000]<-999999
data$g2_1year.cleaned[data$g2_1month>2000 & data$g2_3month>2000 & data$g2_1year>2000]<-999999
data$g2_1year.cleaned[data$g2_1month<100 & data$g2_3month<100 & data$g2_1year<100]<-999999
# What criteria should we use? For the gold and stock markets, the respondents had to say
# what the price of an asset that is worth $1000 today would be in 1 month, 3 months and 1 year,
# so for those markets I'd truncate respondents who had:
#
# 1. At least one reply >4000
# 2. All replies <100 or >2000
### truncation statistics
n<-length(which(!is.na(data$h2_1month)))
na<-length(which(is.na(data$h2_1month)))
na2<-length(which(is.na(data$h2_1month.cleaned)))
summary(data$h2_1year.cleaned)
data<-panel.uh
data$h2_1month.cleaned<-data$h2_1month
data$h2_3month.cleaned<-data$h2_3month
data$h2_1year.cleaned<-data$h2_1year
summary(data$h2_1year.cleaned)
data$h2_1month.cleaned[data$h2_1month>2*data$housing.price|data$h2_1month<0.5*data$housing.price|
data$h2_3month>2*data$housing.price|data$h2_3month<0.5*data$housing.price|
data$h2_1year>2*data$housing.price|data$h2_1year<0.5*data$housing.price]<-999999
summary(data$h2_1month.cleaned)
data$h2_3month.cleaned[data$h2_1month>2*data$housing.price|data$h2_1month<0.5*data$housing.price|
data$h2_3month>2*data$housing.price|data$h2_3month<0.5*data$housing.price|
data$h2_1year>2*data$housing.price|data$h2_1year<0.5*data$housing.price]<-999999
data$h2_1year.cleaned[data$h2_1month>2*data$housing.price|data$h2_1month<0.5*data$housing.price|
data$h2_3month>2*data$housing.price|data$h2_3month<0.5*data$housing.price|
data$h2_1year>2*data$housing.price|data$h2_1year<0.5*data$housing.price]<-999999
data<-panel.uh
data$h2_1month.cleaned<-data$h2_1month
data$h2_3month.cleaned<-data$h2_3month
data$h2_1year.cleaned<-data$h2_1year
data$h2_1month.cleaned[data$h2_1month>2*data$housing.price|data$h2_1month<0.5*data$housing.price|
data$h2_3month>2*data$housing.price|data$h2_3month<0.5*data$housing.price|
data$h2_1year>2*data$housing.price|data$h2_1year<0.5*data$housing.price]<-999999
data$h2_3month.cleaned[data$h2_1month>2*data$housing.price|data$h2_1month<0.5*data$housing.price|
data$h2_3month>2*data$housing.price|data$h2_3month<0.5*data$housing.price|
data$h2_1year>2*data$housing.price|data$h2_1year<0.5*data$housing.price]<-999999
data$h2_1year.cleaned[data$h2_1month>2*data$housing.price|data$h2_1month<0.5*data$housing.price|
data$h2_3month>2*data$housing.price|data$h2_3month<0.5*data$housing.price|
data$h2_1year>2*data$housing.price|data$h2_1year<0.5*data$housing.price]<-999999
data$e2_1month.cleaned<-data$e2_1month
data$e2_3month.cleaned<-data$e2_3month
data$e2_1year.cleaned<-data$e2_1year
data$e2_1month.cleaned[data$e2_1month>4000|data$e2_3month>4000|data$e2_1year>4000]<-999999
data$e2_1month.cleaned[data$e2_1month>2000 & data$e2_3month>2000 & data$e2_1year>2000]<-999999
data$e2_1month.cleaned[data$e2_1month<100 & data$e2_3month<100 & data$e2_1year<100]<-999999
data$e2_3month.cleaned[data$e2_1month>4000|data$e2_3month>4000|data$e2_1year>4000]<-999999
data$e2_3month.cleaned[data$e2_1month>2000 & data$e2_3month>2000 & data$e2_1year>2000]<-999999
data$e2_3month.cleaned[data$e2_1month<100 & data$e2_3month<100 & data$e2_1year<100]<-999999
data$e2_1year.cleaned[data$e2_1month>4000|data$e2_3month>4000|data$e2_1year>4000]<-999999
data$e2_1year.cleaned[data$e2_1month>2000 & data$e2_3month>2000 & data$e2_1year>2000]<-999999
data$e2_1year.cleaned[data$e2_1month<100 & data$e2_3month<100 & data$e2_1year<100]<-999999
data$g2_1month.cleaned<-data$g2_1month
data$g2_3month.cleaned<-data$g2_3month
data$g2_1year.cleaned<-data$g2_1year
data$g2_1month.cleaned[data$g2_1month>4000|data$g2_3month>4000|data$g2_1year>4000]<-999999
data$g2_1month.cleaned[data$g2_1month>2000 & data$g2_3month>2000 & data$g2_1year>2000]<-999999
data$g2_1month.cleaned[data$g2_1month<100 & data$g2_3month<100 & data$g2_1year<100]<-999999
data$g2_3month.cleaned[data$g2_1month>4000|data$g2_3month>4000|data$g2_1year>4000]<-999999
data$g2_3month.cleaned[data$g2_1month>2000 & data$g2_3month>2000 & data$g2_1year>2000]<-999999
data$g2_3month.cleaned[data$g2_1month<100 & data$g2_3month<100 & data$g2_1year<100]<-999999
data$g2_1year.cleaned[data$g2_1month>4000|data$g2_3month>4000|data$g2_1year>4000]<-999999
data$g2_1year.cleaned[data$g2_1month>2000 & data$g2_3month>2000 & data$g2_1year>2000]<-999999
data$g2_1year.cleaned[data$g2_1month<100 & data$g2_3month<100 & data$g2_1year<100]<-999999
n<-length(which(!is.na(data$h2_1month)))
na<-length(which(is.na(data$h2_1month)))
na2<-length(which(is.na(data$h2_1month.cleaned)))
n1
na
na2
source('~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/R/extra/truncation filter original.R', echo=TRUE)
tr
library(stargazer)
stargazer(tr)
rm(list=ls())
load("/Users/manguito/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/R/panel MSA 5 July 2016.dta")
rm(list=ls())
data<-read.csv("/Users/manguito/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/panel_July2016.csv")
length(which(is.na(data$msa)))
data$msa<-as.character(data$msa)
length(which(is.na(data$msa)))
length(which(data$msa==""))
no.msa<-data[data$msa=="",]
length(unique(no.msa$prim_key))
length(unique(data$prim_key))
View(no.msa)
length(which(no.msa$city==""))
table(no.msa$h1_alternate)
2221+2510+917
source('~/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/R/create panel.R', echo=TRUE)
source("/Users/manguito/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/R/match double q and financial crisis respondents.R")
rm(list=ls())
######
load("/Users/manguito/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/R/panel_uh.RData")
source("/Users/manguito/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/R/extra/truncation filter original.R")
source("/Users/manguito/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/R/extra/prepare time invariant variables.R")
data<-data[data$state!="PUERTO RICO",]
length(which(is.na(data$region8)))
test<-subset(data,select=c("prim_key","period","pi.e.1m.e","pi.e.1m.e.new","pi.e.1m.g","pi.e.1m.g.new","pi.e.1m.h","pi.e.1m.h.new"))
View(test)
log(110)-log(100)
(110-100)/110*100
1000*exp(14.63)
10*exp(14.63)
14.63/300+log(1000)
exp(6.9)
10^6.9
log(10)
exp(2.302585)
exp(6.956522)
(49.975)/10
# SAVE INDIVIDUAL LEVEL DATA ######################
library(foreign)
setwd("/Users/manguito/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/csv/")
write.csv(data,file = "panel_July2016.csv")
setwd("/Users/manguito/Dropbox/Double Survey Q Project (2)/econometric analysis ida 2016/data/stata/")
write.dta(data, file="panel_July2016.dta")
